<template>
  <div>
    <van-picker show-toolbar title="标题" :columns="columns" :default-index="value" @change="onChange"  @confirm="updateGender"
  @cancel="$emit('close')"/>
  </div>
</template>

<script>
import { updateProfile } from '@/api/user'
export default {
  name: 'editName',
  data () {
    return {
      columns: ['男', '女'],
      gender: this.value
    }
  },
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  components: {},

  computed: {},
  methods: {
    async updateGender () {
      this.$toast.loading({
        message: '加载中',
        forbidClick: true,
        duration: 0 // 持续展示 toast
      })
      try {
        await updateProfile({
          gender: this.gender
        })
        this.$toast.success('修改成功')
        this.$emit('colse')
        this.$emit('input', this.gender)
      } catch (err) {
        this.$toast.success('修改失败')
      }
    },
    onChange (picker, value, index) {
      // this.$toast(`当前值：${value}, 当前索引：${index}`)
      this.gender = index
    }
  }
}
</script>

<style lang='less' scoped>
.box{
    padding: 20px;
}
</style>
